import {defineStore} from 'pinia'

export const settingStore = defineStore({
    id: 'settingStore',
    state: () => ({
        //菜单导航
        sidebar: {
            opened: true,
            withoutAnimation: false
        },
        //页面是否缓存
        cachedViews: [],
        //其他设置
        setting: {
            title: '数字化油库',
            showLeftMenu: true,
            sidebarLogo: true,
            showNavbarTitle: false,
            showHamburger: true,
            showTagsView: true,
            tagsViewNum: 6,
            showTopNavbar: true,
            permissionMode: 'roles',
        }
    }),
    getters: {},
    actions: {
        // M_settings: (state, data) => {
        //     state.settings = { ...state.settings, ...data }
        // },
        M_sidebar_opened(data) {
            this.sidebar.opened = data
        },
        M_toggleSideBar(ss) {
            this.sidebar.opened = !this.sidebar.opened
        },
        /*keepAlive缓存*/
        M_ADD_CACHED_VIEW(view) {
            // if(this.cachedViews.includes(view)) return
            this.cachedViews.push(view)
        },
        M_DEL_CACHED_VIEW(view) {
            const index = this.cachedViews.indexOf(view)
            index > -1 && this.cachedViews.splice(index, 1)
        },
        M_RESET_CACHED_VIEW: (state) => {
            this.cachedViews = []
        }
    }
})
